﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace Ivy.Common.Framework.Configuration
{
    /// <summary>
    /// This calss represents individual elements inside the main config section.
    /// There are main two type of elements (1) collection of elements (2) individual stand alone element.
    /// In this case it is a individual stand alone element, in this case it has to be inherited from 'ConfigurationElement'
    /// Check the below example
    /// Example <FrameworkIvyConfigSection> is the main config section
    /// Example     <SmtpMailServers>       is the immediate child noide
    /// Example          <add name="MailServerOne" smtpHost="smtp.domain1.com" smtpPort="587" isHostSSLEnabled="true" smtpAuthUserId="useridOne" smtpAuthUserPassword="aaaaaa" isPasswordEncrypted="false" />
    /// Example          <add name="MailServerTwo" smtpHost="smtp.domain2.com" smtpPort="25" isHostSSLEnabled="false" smtpAuthUserId="useridTwo" smtpAuthUserPassword="??????" isPasswordEncrypted="true" />
    /// Example     </SmtpMailServers>
    /// Example </FrameworkIvyConfigSection>
    /// In this case this class represents each XML node inside <SmtpMailServers>
    /// </summary>
    public sealed class SmtpServer : ConfigurationElement
    {
        /// <summary>
        /// These constants represents the attributre tags as represented in the XML
        /// Check the below example
        /// Example <FrameworkIvyConfigSection> is the main config section
        /// Example     <SmtpMailServers>       is the immediate child noide
        /// Example          <add name="MailServerOne" smtpHost="smtp.domain1.com" smtpPort="587" isHostSSLEnabled="true" smtpAuthUserId="useridOne" smtpAuthUserPassword="aaaaaa" isPasswordEncrypted="false" />
        /// Example          <add name="MailServerTwo" smtpHost="smtp.domain2.com" smtpPort="25" isHostSSLEnabled="false" smtpAuthUserId="useridTwo" smtpAuthUserPassword="??????" isPasswordEncrypted="true" />
        /// Example     </SmtpMailServers>
        /// Example </FrameworkIvyConfigSection>
        /// THESE ARE CASE SENSETIVE
        /// </summary>
        #region Variables & Constants
        const string _ConfigPropName = "name";
        const string _ConfigPropSmtpHost = "smtpHost";
        const string _ConfigPropSmtpPort = "smtpPort";
        const string _ConfigPropIsHostSSLEnabled = "isHostSSLEnabled";
        const string _ConfigPropSmtpAuthUserId = "smtpAuthUserId";
        const string _ConfigPropSmtpAuthUserPassword = "smtpAuthUserPassword";
        const string _ConfigPropIsPasswordEncrypted = "isPasswordEncrypted";
        #endregion Variables & Constants

        #region Constructor & Destructor
        #endregion Constructor & Destructor

        /// <summary>
        /// All the property declaration to be done.
        /// There can be only one 'IsKey = true'
        /// </summary>
        #region Public Properties
        [ConfigurationProperty(_ConfigPropName, DefaultValue = "", IsKey = true, IsRequired = true)]
        public string Name
        {
            get
            {
                return this[_ConfigPropName] as string;
            }
        }

        [ConfigurationProperty(_ConfigPropSmtpHost, DefaultValue = "", IsKey = false, IsRequired = true)]
        public string SmtpHost
        {
            get
            {
                return this[_ConfigPropSmtpHost] as string;
            }
        }

        [ConfigurationProperty(_ConfigPropSmtpPort, DefaultValue = "", IsKey = false, IsRequired = true)]
        public string SmtpPort
        {
            get
            {
                return this[_ConfigPropSmtpPort] as string;
            }
        }

        [ConfigurationProperty(_ConfigPropIsHostSSLEnabled, DefaultValue = "false", IsKey = false, IsRequired = false)]
        public string IsHostSSLEnabled
        {
            get
            {
                return this[_ConfigPropIsHostSSLEnabled] as string;
            }
        }

        [ConfigurationProperty(_ConfigPropSmtpAuthUserId, DefaultValue = "", IsKey = false, IsRequired = true)]
        public string SmtpAuthUserId
        {
            get
            {
                return this[_ConfigPropSmtpAuthUserId] as string;
            }
        }
        [ConfigurationProperty(_ConfigPropSmtpAuthUserPassword, DefaultValue = "", IsKey = false, IsRequired = true)]
        public string SmtpAuthUserPassword
        {
            get
            {
                return this[_ConfigPropSmtpAuthUserPassword] as string;
            }
        }
        [ConfigurationProperty(_ConfigPropIsPasswordEncrypted, DefaultValue = "false", IsKey = false, IsRequired = false)]
        public string IsPasswordEncrypted
        {
            get
            {
                return this[_ConfigPropIsPasswordEncrypted] as string;
            }
        }

        #endregion Public Properties

        #region Public Methods
        #endregion Public Methods

        #region Events
        #endregion Events

        #region Private Methods
        #endregion Private Methods
    }
}
